package Test;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: LianBao
 * Date: 2024-03-12
 * Time: 19:14
 */
public class demo1 {

    public static void main(String[] args) {
        try {
            int[] a = {1, 2, 3, 4};
            System.out.println(10 / 0);
            System.out.println("11111111111111");
            a = null;
            System.out.println(a[100]);
        } catch (ArithmeticException | NullPointerException e) {
            System.out.println("出现异常");
        }
    }

    public static void main2(String[] args) {
        try {
            int[] a = {1, 2, 3, 4};
            System.out.println(10 / 0);
            System.out.println("11111111111111");
            a = null;
            System.out.println(a[100]);
        } catch (ArithmeticException e) {
//            e.printStackTrace();//可以打印异常的信息,定位异常出现的位置
            System.out.println("算术异常");
        } catch (NullPointerException n) {
            System.out.println("空指针异常");
        }
    }

    public static void main1(String[] args) {
        try {
            System.out.println("-----------------------");
            System.out.println(10 / 0);
            System.out.println("11111111111111");
        } catch (ArithmeticException e) {
            e.printStackTrace();//可以打印异常的信息,定位异常出现的位置
            System.out.println("异常");
        }
    }
}
